/**
 * 以puppter的方式直接解析并运行json
 * @author mumulin
 * @email xinglinhe@qq.com
 * @date 2025/11
 */
import readlineSync from 'readline-sync'
import base,{
	jump,action_click,action_delay,
	action_jumpIndex,action_reStep,action_replayCheck,
	action_pageClick,action_replace,action_fileUpload
} from '../../lib/base.js'
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url); // 当前文件的绝对路径
const __dirname = dirname(__filename); // 当前文件所在目录的绝对路径

async function acceptCookies(page){
	return
	try{
		await page.waitForSelector("#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll",{
			timeout: 500
		})
		await page.click("#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll")
	}catch(e){}
}

class dataWork {
    constructor() {}
	async signIn({data, step, index, page}){
		const option = [
			{runType : action_replace, target : "aria/Email Address",type:"change", replace: {value:data.account.Email}},
			{runType : action_fileUpload, target : "#selfile",type:"click", files: `${__dirname}/Fw：文本和文件测试.pdf` },
			{runType : action_fileUpload, target : "#selfile2",type:"click", files: `${__dirname}/Fw：文本和文件测试.pdf` },
		]
		return await base.eventTrusteeshipAll({data, step, index, page, option})
	}
}

export default {
	// 基础运行分发
	async run(params) {
		const work =  new dataWork();
		const stepsName = params.stepsName?.trim()||null
		if(!stepsName) return
		await acceptCookies(params.page)
		if(work[stepsName]) return await work[stepsName](params);
	}
}